home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Creative Computers
/
Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso
/
shareware
/
games
/
uchess
/
src
/
nondsp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-17
|
22KB
|
994 lines
/*
* nondsp.c - UNIX & MSDOS NON-DISPLAY, AND CHESSTOOL interface for Chess
*
* Copyright (c) 1988,1989,1990 John Stanback
* Copyright (c) 1992 Free Software Foundation
*
* This file is part of GNU CHESS.
*
* GNU Chess is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GNU Chess is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Chess; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <ctype.h>
#include <signal.h>
#ifdef AMIGA
#define __USE_SYSBASE
#include <exec/types.h>
#include <exec/exec.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#endif
char __far HintString[80];
#define SIGQUIT SIGINT
#include "gnuchess.h"
#ifdef MSDOS
#include <dos.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#else
#include <dos.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/*
#include <sys/param.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/ioctl.h>
*/
#endif
extern short int ISZERO;
char __aligned __far IllegalString[40];
extern int AmigaStarted;
extern int __aligned global_tmp_score;
extern int __aligned previous_score;
int __aligned IllegalMove=0;
int __aligned Mate=0;
int __aligned DrawnGame=0;
char __far __aligned MateString[40]={0};
extern long OrigResponse;
#ifdef DEBUG
INTSIZE int __aligned debuglevel = 0;
#endif /* DEBUG */
unsigned INTSIZE int __aligned MV[MAXDEPTH];
int __aligned MSCORE;
#if defined CHESSTOOL || defined XBOARD
INTSIZE int __aligned chesstool = 1;
#else
INTSIZE int __aligned chesstool = 0;
#endif /* CHESSTOOL */
extern char mvstr[4][6];
int __aligned mycnt1, mycnt2;
char __aligned *DRAW;
extern char *InPtr;
extern INTSIZE int pscore[];
void
Initialize (void)
{
mycnt1 = mycnt2 = 0;
#if defined CHESSTOOL || defined XBOARD
#ifndef SYSV
/* setlinebuf (stdout);*/
#else
/* setvbuf (stdout, NULL, _IOLBF, BUFSIZ);*/
#endif
/* printf (CP[43]);*/ /*Chess*/
if (!TCflag && (MaxResponseTime == 0))
MaxResponseTime = 15L*100L;
#endif /* CHESSTOOL */
}
void DoAMove(void);
void DoAMove()
{
char astr[40];
int r,c,l;
char piece;
r = mvstr[0][3] - '1';
c = mvstr[0][2] - 'a';
l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
if (color[l] == neutral)
{
DisplayBeep(0L);
Delay(25L);
DisplayBeep(0L);
Delay(25L);
DisplayBeep(0L);
Delay(25L);
piece = ' ';
}
else if (color[l] == white)
piece = qxx[board[l]]; /* white are lower case pieces */
else
piece = pxx[board[l]]; /* black are upper case pieces */
if (computer == black)
sprintf(astr,"%d: %s",GameCnt>>1,mvstr[0]);
else
sprintf(astr,"%d: %s",(GameCnt+1)>>1,mvstr[0]);
DisplayComputerMove(astr);
AnimateAmigaMove(mvstr[0],piece);
}
void
ExitChess (void)
{
/* signal (SIGTERM, SIG_IGN);*/
ListGame (0L);
#ifdef AMIGA
if (AmigaStarted)
AmigaShutDown();
#endif
exit (0);
}
#ifndef MSDOS /* never called!!! */
#ifndef AMIGA
void
Die (int sig)
{
char s[80];
ShowMessage (CP[31]); /*Abort?*/
scanz ("%s", s);
if (strcmp (s, CP[210]) == 0) /*yes*/
ExitChess ();
}
#endif
#endif /* MSDOS */
void
TerminateSearch (int sig)
{
#ifdef MSDOS
sig++; /* shut up the compiler */
#endif /* MSDOS */
if (!flag.timeout)
flag.musttimeout = true;
flag.bothsides = false;
}
void
help (void)
{
#ifndef AMIGA
ClrScreen ();
/*printz ("CHESS command summary\n");*/
printz (CP[40]);
printz ("----------------------------------------------------------------\n");
/*printz ("g1f3 move from g1 to f3 quit Exit Chess\n");*/
printz (CP[158]);
/*printz ("Nf3 move knight to f3 beep turn %s\n", (flag.beep) ? "off" : "on");*/
printz (CP[86], (flag.beep) ? CP[92] : CP[93]);
/*printz ("a7a8q promote pawn to queen\n");*/
printz (CP[128], (flag.material) ? CP[92] : CP[93]);
/*printz ("o-o castle king side easy turn %s\n", (flag.easy) ? "off" : "on");*/
printz (CP[173], (flag.easy) ? CP[92] : CP[93]);
/*printz ("o-o-o castle queen side hash turn %s\n", (flag.hash) ? "off" : "on");*/
printz (CP[174], (flag.hash) ? CP[92] : CP[93]);
/*printz ("bd redraw board reverse board display\n");*/
printz (CP[130]);
/*printz ("list game to chess.lst book turn %s used %d of %d\n", (Book) ? "off" : "on", bookcount, BOOKSIZE);*/
printz (CP[170], (Book) ? CP[92] : CP[93], bookcount, BOOKSIZE);
/*printz ("undo undo last ply remove take back a move\n");*/
printz (CP[200]);
/*printz ("edit edit board force enter game moves\n");*/
printz (CP[153]);
/*printz ("switch sides with computer both computer match\n");*/
printz (CP[194]);
/*printz ("white computer plays white black computer plays black\n");*/
printz (CP[202]);
/*printz ("depth set search depth clock set time control\n");*/
printz (CP[149]);
/*printz ("post principle variation hint suggest a move\n");*/
printz (CP[177]);
/*printz ("save game to file get game from file\n");*/
printz (CP[188]);
/*printz ("random randomize play new start new game\n");*/
printz (CP[181]);
printz ("----------------------------------------------------------------\n");
/*printz ("Computer: %-12s Opponent: %s\n",*/
printz (CP[46],
ColorStr[computer], ColorStr[opponent]);
/*printz ("Depth: %-12d Response time: %d sec\n",*/
printz (CP[51],
MaxSearchDepth, MaxResponseTime/100);
/*printz ("Random: %-12s Easy mode: %s\n",*/
printz (CP[99],
(dither) ? CP[93] : CP[92], (flag.easy) ? CP[93] : CP[92]);
/*printz ("Beep: %-12s Transposition file: %s\n",*/
printz (CP[36],
(flag.beep) ? CP[93] : CP[92], (flag.hash) ? CP[93] : CP[92]);
/*printz ("Time Control %s %d moves %d seconds %d opr %d depth\n", (TCflag) ? "ON" : "OFF",*/
printz (CP[110], (TCflag) ? CP[93] : CP[92],
TimeControl.moves[white], TimeControl.clock[white] / 100, OperatorTime, MaxSearchDepth);
signal (SIGINT, TerminateSearch);
#ifndef MSDOS
signal (SIGQUIT, TerminateSearch);
#endif /* MSDOS */
#endif
}
void
EditBoard (void)
/*
* Set up a board position. Pieces are entered by typing the piece followed
* by the location. For example, Nf3 will place a knight on square f3.
*/
{
INTSIZE a, r, c, sq, i, found;
int tmpcolor;
char s[80];
flag.regularstart = false;
Book = 0;
#ifndef AMIGA
/*printz (". exit to main\n");*/
printz (CP[29]);
/*printz ("# clear board\n");*/
printz (CP[28]);
/*printz ("c change sides\n");*/
printz (CP[136]);
/*printz ("enter piece & location: \n");*/
printz (CP[155]);
#else
if (!OpenAmigaEditWindow())
{ /* open the window which will give us back text string */
DisplayBeep(0L);
Delay(25L);
DisplayBeep(0L);
return;
}
#endif
a = tmpcolor = white;
do
{
GetEditText(s,&tmpcolor); /* amiga routine to get the command from user */
found=0;
if (s[0] == CP[28][0]) /*#*/
for (sq = 0; sq < 64; sq++)
{
board[sq] = no_piece;
color[sq] = neutral;
}
if (a != tmpcolor) /*c*/
a = otherside[a];
c = s[1] - 'a';
r = s[2] - '1';
if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
{
sq = locn (r, c);
color[sq] = a;
board[sq] = no_piece;
for (i = no_piece; i <= king; i++)
if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
{
board[sq] = i;
found=1;
break;
}
if ((found==0)||(board[sq] == no_piece)) color[sq] = neutral;
}
} while (s[0] !